<template>
    <!-- 食堂用餐人员管理 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search" @onSelectChange="handelSelectChange"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name title="日常用餐人员管理"></title-name> -->
            <a-alert class="mb12 mt12" type="info" show-icon>
                <template slot="message">
                    <span>
                        日常用餐总人数
                        <a>{{ form.total }}</a>
                        人
                    </span>
                </template>
            </a-alert>
            <list-table
                ref="table"
                row-key="id"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
            >
            <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
                <template slot="status" slot-scope="text, record">
                    <span :class="record.status == 0 ? 'del_btn' : ''">{{ record.statusName }}</span>
                </template>
                <template slot="action" slot-scope="text, record">
                    <!-- <a @click="handleManage(0, record)">查看</a>
                    <a-divider type="vertical"></a-divider> -->
          <!-- <a @click="handleManage(1, record)">编辑</a> -->
          <!-- 删除 -->
          <!-- <a-divider v-if="record.status == 0" type="vertical"></a-divider> -->
          <a
            v-if="record.status == 0"
            @click="handleUpdate(record.id)"
          >办理</a>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
// import { STable } from '@/components' // 表格
import { getPageOfficeCanteenPeopleManage, updatePeople, getOfficeCanteenPeopleManageSum } from '@/api/office/canteen' // api
import Selector from '@/components/Select/Selector'
import BasePage from '@/views/basePage' // 基础配置
import SelectCompanyAndProject from '@/components/Select/SelectCompanyAndProject'
import OrgTreeSelect from '@/components/OrgTreeSelect/index'
const searchArr = [
    // 搜索框
    {
        name: '单位',
        valueKey: 'searchQuery',
        type: OrgTreeSelect,
    },
    {
        name: '用餐人姓名',
        type: 'input',
        value: 'name',
    },
]
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        scopedSlots: { customRender: 'index' }
    },
    {
        title: '用餐人姓名',
        dataIndex: 'name',
    },
    {
        title: '所属单位',
        ellipsis: true,
        dataIndex: 'unitName',
    },
    {
        title: '所属部门',
        ellipsis: true,
        dataIndex: 'departmentName',
    },
    {
        title: '餐卡等事项办理状态',
        ellipsis: true,
        dataIndex: 'status',
        scopedSlots: { customRender: 'status' },
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: '180px',
        align: 'center',
        scopedSlots: { customRender: 'action' },
    },
]
export default {
  name:'a'+Date.now(),
  extends: new BasePage(),
    components: {
        // STable,
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {}, // 查询参数
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
                this.getOfficeCanteenPeopleManageSum(requestParameters.query)
                return getPageOfficeCanteenPeopleManage(requestParameters).then((res) => {
                    return res
                })
            }, // 加载数据方法 必须为 Promise 对象
            updateApi: { update: updatePeople }, // api
            editModel: 0,
            form: {},
            position: '',
        }
    },
    mounted() {
        this.position = this.$currentPost()?.postCode
    },
    methods: {
        handelSelectChange(data) {
        if(this.isInited) return
            this.isInited = true
            this.$nextTick(() => {
                this.search({
                    unitId: data?.id || ''
                })
            })
        },
        getOfficeCanteenPeopleManageSum(requestParameters) {
            getOfficeCanteenPeopleManageSum(requestParameters).then((res) => {
                this.form = res.data
            })
        },
        // 搜索
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        // 操作栏
        handleManage(type, record) {
            this.editModel = type
            let query = {
                editModel: type,
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: '/office/propertyManagement/leaseContract/updateLeaseContract',
                query,
            })
        },
    },
}
</script>
